package com.baomidou.plugin.idea.mybatisx.advance.processor.clazz;

import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.plugin.idea.mybatisx.advance.util.PsiMethodUtil;
import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiMethod;
import org.jetbrains.annotations.NotNull;

import java.util.Collection;
import java.util.Collections;

/**
 * 给po的每个属性都生成一个list方法
 * @author wanglei
 */
public class ListProcessor extends AbstractMPOnceMethodGenClassProcessor {

    private static final String CLASS_NAME = TableName.class.getName();

    public static final String METHOD_NAME = "list";

    public ListProcessor() {
        super(CLASS_NAME, PsiMethod.class);
    }

    @Override
    String getMethodName() {
        return METHOD_NAME;
    }

    @NotNull
    public Collection<PsiMethod> createToStringMethod(@NotNull PsiClass psiClass, @NotNull PsiElement psiNavTargetElement) {
        final StringBuilder builder = new StringBuilder();
        try {
            builder.append("public java.util.List<" + psiClass.getName() + "> list(){return new java.util.ArrayList<" + psiClass.getName() + ">();} ");
            return Collections.singletonList(PsiMethodUtil.createMethod(psiClass, builder.toString(), psiNavTargetElement));
        } finally {
            //StringBuilderSpinAllocator.dispose(builder);
        }
    }

}
